package com.sky.servlet;

import com.sky.dao.NoticeDao;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
//
@WebServlet("/noticeDel.jsp")
    public class NoticeDelServlet extends HttpServlet {
        @Override
        protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
            String user =(String) req.getSession().getAttribute("User");//获取会话
            if (user==null || user.equals("")){
                resp.sendRedirect("login.jsp");//没登录 跳转到登陆页面
                return;
            }
            int NoticeId = Integer.parseInt(req.getParameter("NoticeId"));
            int result = (new NoticeDao()).delete(NoticeId);
            if (result > 0) {
                resp.sendRedirect("notice.jsp");
            } else {

                req.setAttribute("msg", "删除失败");
                req.setAttribute("url", "notice.jsp");
                req.getRequestDispatcher("WEB-INF/error.jsp").forward(req, resp);
            }

        }
        }

